import {ref} from 'vue'
import {RouterView} from './RouterView'
import {RouterLink} from './RouterLink'
export function createRouter({mode = "hash",routers}:any){
  const routerStore :any= [];
  const currentRoute = ref({
    path:'/app2',
    to:'',
  });
  const currentRouteKey = "currentRouteKey"
  const routerInstanceKey = "routerInstanceKey"


  const push = (val)=>{
    currentRoute.value.path = val;
  }

  const addRouter = (router)=>{ 
    routerStore.push(router);
  }

  const gerRouter = (val)=>{
    return routerStore.find(item =>item.path === val)
  }
  routers.forEach(element => {
    addRouter(element);
  });
  const routerInstance = {
    currentRoute,
    routerStore,
    push,
    addRouter,
    gerRouter,
    install(app:any){
      const router = this
      app.config.globalProperties.$router = router;
      app.provide(currentRouteKey, currentRoute);
      app.provide(routerInstanceKey, routerInstance);
      app.component("RouterLink",RouterLink);
      app.component("RouterView",RouterView);
    }
  }

  let a:object = 124

  a = 23
  return routerInstance
} 